package com.scm.web.controller.inventory;

import java.util.List;

import com.scm.common.core.page.PageDomain;
import com.scm.common.core.page.TableSupport;
import com.scm.dto.resp.invent.QueryScmInventoryStashProductPageResp;
import com.scm.dto.resp.invent.ScmInventoryStashProductDo;
import com.scm.persist.model.ScmInventoryStashProduct;
import com.scm.service.IScmInventoryStashProductService;
import com.scm.web.controller.product.ProductVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.scm.common.annotation.Log;
import com.scm.common.enums.BusinessType;
import com.scm.common.core.controller.BaseController;
import com.scm.common.core.domain.AjaxResult;
import com.scm.common.utils.poi.ExcelUtil;
import com.scm.common.core.page.TableDataInfo;

/**
 * 库存-仓库-商品信息Controller
 * 
 * @author reptilemanager
 * @date 2024-03-17
 */
@Controller
@RequestMapping("/scm/inventory/product")
public class ScmInventoryStashProductController extends BaseController
{
    private String prefix = "inventory/product";

    @Autowired
    private IScmInventoryStashProductService scmInventoryStashProductService;

    @RequiresPermissions("system:product:view")
    @GetMapping()
    public String product()
    {
        return prefix + "/product";
    }

    /**
     * 查询库存-仓库-商品信息列表
     */
    @RequiresPermissions("system:product:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ScmInventoryStashProduct scmInventoryStashProduct)
    {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer start = (pageDomain.getPageNum() - 1) * 10;

        QueryScmInventoryStashProductPageResp resp = scmInventoryStashProductService.selectScmInventoryStashProductList(scmInventoryStashProduct,start,pageDomain.getPageSize());

        return toTableDataInfo(Long.valueOf(resp.getTotal()),resp.getList());
    }


    @GetMapping("/popupListPage")
    public String detail( ModelMap mmap)
    {

        return prefix + "/popupProductList";
    }


    @RequiresPermissions("system:product:list")
    @PostMapping("/popupList")
    @ResponseBody
    public TableDataInfo popupListPage(ScmInventoryStashProduct scmInventoryStashProduct)
    {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer start = (pageDomain.getPageNum() - 1) * 10;

        QueryScmInventoryStashProductPageResp resp = scmInventoryStashProductService.selectScmInventoryStashProductList(scmInventoryStashProduct,start,pageDomain.getPageSize());

        return toTableDataInfo(Long.valueOf(resp.getTotal()),resp.getList());
    }


    /**
     * 导出库存-仓库-商品信息列表
     */
    @RequiresPermissions("system:product:export")
    @Log(title = "库存-仓库-商品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ScmInventoryStashProduct scmInventoryStashProduct)
    {
        QueryScmInventoryStashProductPageResp resp  = scmInventoryStashProductService.selectScmInventoryStashProductList(scmInventoryStashProduct,0,10);
        ExcelUtil<ScmInventoryStashProductDo> util = new ExcelUtil<ScmInventoryStashProductDo>(ScmInventoryStashProductDo.class);
        return util.exportExcel(resp.getList(), "库存-仓库-商品信息数据");
    }

    /**
     * 新增库存-仓库-商品信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库存-仓库-商品信息
     */
    @RequiresPermissions("system:product:add")
    @Log(title = "库存-仓库-商品信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ScmInventoryStashProduct scmInventoryStashProduct)
    {
        return toAjax(scmInventoryStashProductService.insertScmInventoryStashProduct(scmInventoryStashProduct));
    }

    /**
     * 修改库存-仓库-商品信息
     */
    @RequiresPermissions("system:product:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ScmInventoryStashProduct scmInventoryStashProduct = scmInventoryStashProductService.selectScmInventoryStashProductById(id);
        mmap.put("scmInventoryStashProduct", scmInventoryStashProduct);
        return prefix + "/edit";
    }

    /**
     * 修改保存库存-仓库-商品信息
     */
    @RequiresPermissions("system:product:edit")
    @Log(title = "库存-仓库-商品信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ScmInventoryStashProduct scmInventoryStashProduct)
    {
        return toAjax(scmInventoryStashProductService.updateScmInventoryStashProduct(scmInventoryStashProduct));
    }

    /**
     * 删除库存-仓库-商品信息
     */
    @RequiresPermissions("system:product:remove")
    @Log(title = "库存-仓库-商品信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(scmInventoryStashProductService.deleteScmInventoryStashProductByIds(ids));
    }

    @PostMapping("/detail/{id}")
    @ResponseBody
    public AjaxResult detail(@PathVariable("id") Long id)
    {

        return AjaxResult.success(scmInventoryStashProductService.getStashProductById(id));

    }

}
